﻿using GalaSoft.MvvmLight.Messaging;
using NicoView.ViewModel;
using NicoView.Model.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using GalaSoft.MvvmLight.Command;
using NicoView.ViewModel.Message;


namespace NicoView.View
{
    /// <summary>
    /// NicoUserAuthSetControl.xaml の相互作用ロジック
    /// </summary>
    public partial class NicoViewUserAuthSetControl : UserControl
    {

        public event NicoViewAuthSetViewModel.AfterRegistration After;
        public NicoViewUserAuthSetControl()
        {
            InitializeComponent();

            After = null;

        }

        public new NicoViewAuthSetViewModel DataContext
        {
            get
            {
                return (NicoViewAuthSetViewModel)base.DataContext;
            }
        }

        public NicoUserAuth Auth
        {
            get
            {
                return DataContext.Auth;
            }
        }

        private ICommand _registCommand;

        public ICommand RegistCommand
        {
            get
            {
                if (_registCommand == null) _registCommand = new RelayCommand(() => 
                { 
                    DataContext.SaveCommand.Execute(null); 
                }, () => 
                {
                    this.Auth.Mail = this.MailText.Text;
                    this.Auth.PassWord = this.PasswordText.Password;
                    return DataContext.SaveCommand.CanExecute(null); 
                });

                return _registCommand;
            }
        }

        private void NicoUserSetControl_Loaded(object sender, RoutedEventArgs e)
        {


            Messenger.Default.Register(this, (Action<GenericMessage<NicoViewAuthSetResultMessage>>)((rslt) =>
            {
                if (After != null) After(rslt.Content.Result);
            }));

            _registCommand = null;
        }





    }
}
